﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="ZX.Web.UI.Controls.DataGrid" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<script src="/SFramework/boot.js"></script>
<body style="margin: 0px; padding: 0px">
    <form id="form1" runat="server">
      <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="fnAdd()">增加</a>
                        <a class="mini-button" iconCls="icon-add" onclick="fnEdit()">编辑</a>
                        <a class="mini-button" iconCls="icon-remove" onclick="fnRemove()">删除</a>  
                        <a class="mini-button" iconCls="icon-remove" onclick="fnGridSave()">保存</a>         
                    </td>
                    <td style="white-space:nowrap;">
                        <input id="key" class="mini-textbox" emptyText="请输入姓名" style="width:150px;" onenter="onKeyEnter"/>   
                        <a class="mini-button" onclick="search()">查询</a>
                    </td>
                </tr>
            </table>           
        </div>
      <div id="treegrid1" class="mini-treegrid" style="width:100%; height:100%;"
            url="../data/jsondata.aspx?entity=<%=EntityName%>&type=1" showtreeicon="true"
            treecolumn="name" idfield="id" parentfield="parent_id" resultastree="false"
            allowresize="true" expandonload="true">
            <div property="columns">
                <div type="indexcolumn"></div>
                <div name="name" field="name" width="160" >菜单名称</div>
                <%=DataFields %>
            </div>
        </div>
    </form>
</body>
<script type="text/javascript">
    var _openWindowHeight=<%=EditWindowHeight%>;
    var _openWindowWidth=<%=EditWindowWidth%>;
    <% =ColumnDataSource%>
    var const_EditEntity = "<%=EditEntity%>";
</script>
<script>
        $("#treegrid1").height($(document).height() - 36);
        mini.parse();
        var grid = mini.get("treegrid1")
        var fnAdd = function () {
            var row = grid.getSelectedNode();
            mini.open({
                url: "/ExtendPage/editview/DefineEditForm.aspx?entity="+const_EditEntity+"&parent_id=" + row.id,
                title: "新增员工", width: _openWindowWidth, height: _openWindowHeight,
                onload: function () {
                    //var iframe = this.getIFrameEl();
                    //var data = { action: "new" };
                    //iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }

        var fnEdit = function () {
            var row = grid.getSelectedNode();
            //debugger
            if (row) {
                mini.open({
                    url: "/ExtendPage/editview/DefineEditForm.aspx?entity="+const_EditEntity+"&id=" + row.id,
                title: "编辑员工", width: _openWindowWidth, height: _openWindowHeight,
                onload: function () {
                    //var iframe = this.getIFrameEl();
                    //var data = { action: "edit", id: row.id };
                    //iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();

                }
            });

            } else {
                alert("请选中一条记录");
            }
    }

        //
        var fnQuciklyQuery = function () {

        }

        var fnRemove = function () {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.id);
                    }
                    var id = ids.join(',');
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "/extendpage/action/datasave.aspx?entity="+const_EditEntity+"&action=delete&id=" + id,
                    success: function (text) {
                        if (text == 1) {
                            alert("删除成功!");
                        }
                        grid.reload();
                    },
                    error: function () {
                    }
                });
            }
        } else {
            alert("请选中一条记录");
        }
    }

    var fnGridSave = function () {
        //debugger
        var data = grid.getChanges();
        var json = mini.encode(data);

        grid.loading("保存中，请稍后......");
        $.ajax({
            url: "/extendpage/action/datasave.aspx?entity="+const_EditEntity+"&action=batch&flag=1",
            data: { data: json },
            type: "post",
            success: function (text) {
                grid.reload();
                alert("批量保存成功!");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }
  </script>